package com.winbomb.kingcard.base;

import com.winbomb.kingcard.IPlayer;
import com.winbomb.kingcard.IStatsInfo;

import android.util.Log;

public class StatsInfo implements IStatsInfo {

	public static final String TAG = "StatsInfo";

	public static final int ST_BATTLE = 0;
	public static final int ST_VICTORY = 1;
	public static final int ST_DEFEATED = 2;
	public static final int ST_CONQUER = 3;
	public static final int ST_BE_CONQUERED = 4;
	public static final int ST_REVITALIZE = 5; // 复活别人的次数
	public static final int ST_BE_REVITALIZED = 6; // 被别人复活的次数
	public static final int ST_KILL_COUNT = 7; // 歼敌个数
	public static final int ST_FINAL_SCORE = 8; // 最后得分

	public static final int KILL_POINT = 0;
	private static final int VICTORY_POINT = 1;
	private static final int DEFEATED_POINT = -1;
	private static final int CONQUER_POINT = 10;
	private static final int REVITALIZE_POINT = 5;
	public static final int BE_REVITALED_POINT = -10;

	/** 被统计的玩家 */
	IPlayer player;

	/** 战斗次数 */
	private int battleCnt;

	/** 战斗胜利次数 */
	private int victoryCnt;

	/** 战斗失败次数 */
	private int defeatedCnt;

	/** 灭掉别的城池的次数 */
	private int conquerCnt;

	/** 被别人灭掉的次数 */
	private int beConqueredCnt;

	/** 复活别人的次数 */
	private int revitalizeCnt;

	/** 被复活的次数 */
	private int beRevitaledCnt;

	/** 歼敌次数 */
	private int killCnt;

	/** 得分 */
	private int score;

	public StatsInfo(IPlayer player) {
		this.player = player;
		this.score = 0;
	}

	/**
	 * 清除统计信息
	 */
	public void clear() {
		this.victoryCnt = 0;
		this.defeatedCnt = 0;
		this.conquerCnt = 0;
		this.beConqueredCnt = 0;
		this.revitalizeCnt = 0;
		this.score = -5;
	}

	@Override
	public void record(int statsId, int count) {
		switch (statsId) {
		case ST_BATTLE:
			battleCnt += count;
			break;
		case ST_VICTORY:
			victoryCnt += count;
			score += count * VICTORY_POINT;
			break;
		case ST_DEFEATED:
			defeatedCnt += count;
			score -= count * VICTORY_POINT;
			break;
		case ST_CONQUER:
			conquerCnt += count;
			score += count * CONQUER_POINT;
			break;
		case ST_BE_CONQUERED:
			beConqueredCnt += count;
			score -= count * CONQUER_POINT;
			break;
		case ST_REVITALIZE:
			revitalizeCnt += count;
			score += count * REVITALIZE_POINT;
			break;
		case ST_KILL_COUNT:
			killCnt += count;
			break;
		case ST_BE_REVITALIZED:
			beRevitaledCnt += count;
			score += count * BE_REVITALED_POINT;
			break;
		case ST_FINAL_SCORE:
			score += count;
			break;
		default:
			Log.w(TAG, "Unknown statistical item, id = " + statsId);
		}

	}

	@Override
	public void record(int statsId) {
		record(statsId, 1);
	}

	@Override
	public int getStats(int statsId) {
		switch (statsId) {
		case ST_BATTLE:
			return battleCnt;
		case ST_VICTORY:
			return victoryCnt;
		case ST_DEFEATED:
			return defeatedCnt;
		case ST_CONQUER:
			return conquerCnt;
		case ST_BE_CONQUERED:
			return beConqueredCnt;
		case ST_KILL_COUNT:
			return killCnt;
		case ST_BE_REVITALIZED:
			return beRevitaledCnt;
		default:
			Log.w(TAG, "Unknown statistical item, id = " + statsId);
			return 0;
		}
	}

	public int getExploit() {

		// 得分规则
		// 1. 胜利一场得1分
		// 2. 失败一场减1分
		// 3. 征服一次,征服者得10分,被征服者扣10分
		// 4. 复活一次,主公得5分,被复活者扣5分

		int point = victoryCnt * VICTORY_POINT // 胜利得分
				+ (battleCnt - victoryCnt) * DEFEATED_POINT // 失败扣分
				+ conquerCnt * CONQUER_POINT // 征服得分
				- beConqueredCnt * CONQUER_POINT // 被征服扣分
				+ revitalizeCnt * REVITALIZE_POINT // 复活得分
				- beRevitaledCnt * REVITALIZE_POINT; // 被俘后扣分

		return point;
	}

	@Override
	public int getScore() {
		return this.score;
	}
}
